package com.prawn.ift_baseconfig.controller;

import com.prawn.ift_baseconfig.pojo.Network;
import com.prawn.ift_baseconfig.service.NetWorkService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 网络信息管理
 */
@Controller
public class NetWorkController {

    @Autowired
    private NetWorkService netWorkService;

    /**
     * 添加网络信息
     * @Param
     * @return Result
     */
    @RequestMapping("/network/add")
    @ResponseBody
    public Result add(Network network) {
        network.setId(UUID.randomUUID().toString().replaceAll("-",""));
        network.setCreateDate(new Date());
        network.setUpdateDate(new Date());
        return netWorkService.addNetWork(network);
    }

    /**
     * 删除网络信息
     * @Param id
     * @return Result
     */
    @RequestMapping("/network/delete")
    @ResponseBody
    public Result delete(String id) {
        return netWorkService.deleteNetWork(id);
    }

    /**
     * 修改网络信息
     * @Param
     * @return Result
     */
    @RequestMapping("/network/edit")
    @ResponseBody
    public Result edit(Network network) {
        network.setCreateDate(null);
        network.setUpdateDate(new Date());
        return netWorkService.editNetWork(network);
    }

    /**
     * 查询网络信息
     * @return Network
     */
    @RequestMapping("/network/{id}")
    @ResponseBody
    public Network get(@PathVariable String id) {
        return netWorkService.getNetWorkById(id);
    }

    /**
     * 查询设备id的网络信息
     * @return Network
     */
    @RequestMapping("/network/equipment/{equipmentId}")
    @ResponseBody
    public Result getByequipmentId(@PathVariable String equipmentId) {

        return netWorkService.getNetWorkByequipmentId(equipmentId);
    }

    /**
     * 查询网络信息列表
     * @return Result
     */
    @RequestMapping("/network/list")
    @ResponseBody
    public Result getList() {
        return netWorkService.getNetWorkList();
    }

    /**
     * 分页查询网络信息列表
     * @return Result
     */
    @RequestMapping("/network/page")
    @ResponseBody
    public Result getPage(int page,int limit) {
        return netWorkService.getNetWorkPage(page,limit);
    }

}
